Question: A function $f$ is defined recursively by $f(1)=f(2)=1$ and \[f(n)=f(n-1)-f(n-2)+n\]for all integers $n \geq 3$. What is $f(2018)$?
Solution: Let $g(n) = f(n) - n.$  Then $f(n) = g(n) + n,$ so
\[g(n) + n = g(n - 1) + (n - 1) - g(n - 2) - (n - 2) + n.\]This simplifies to
\[g(n) = g(n - 1) + g(n - 2) + 1.\]Also, $g(1) = 0$ and $g(2) = -1,$ so
\begin{align*}
g(3) &= (-1) - 0 + 1 = 0, \\
g(4) &= 0 - (-1) + 1 = 2, \\
g(5) &= 2 - 0 + 1 = 3, \\
g(6) &= 3 - 2 + 1 = 2, \\
g(7) &= 2 - 3 + 1 = 0, \\
g(8) &= 0 - 2 + 1 = -1.
\end{align*}Since $g(7) = g(1) = 0$ and $g(8) = g(2) = -1,$ and each term depends only on the two previous terms, the sequence $g(n)$ is periodic from here on, with a period of length 6.  Therefore, $g(2018) = g(2) = -1,$ so $f(2018) = g(2018) + 2018 = \boxed{2017}.$